package org.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.example.entity.User;
import org.example.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    // 1. 根据用户编号与密码查询用户信息
    @GetMapping("/getUserByIdByPass")
    public User getUserByIdByPass(@RequestParam("userId") String userId, @RequestParam("password") String password) {
        return userService.getUserByIdByPass(userId, password);
    }

    // 2. 根据用户编号查询用户表返回的行数
    @GetMapping("/getUserById")
    public int getUserById(@RequestParam("userId") String userId) {
        return userService.getUserById(userId);
    }

    // 3. 向用户表中添加一条记录
    @PostMapping("/saveUser")
    public int saveUser(@RequestParam("userId") String userId, @RequestParam("password") String password,
            @RequestParam("userName") String userName, @RequestParam("userSex") Integer userSex) {
        return userService.saveUser(userId, password, userName, userSex);
    }
}